home *** CD-ROM | disk | FTP | other *** search
/ SGI Freeware 1999 August / SGI Freeware 1999 August.iso / dist / fw_exim.idb / usr / freeware / catman / p_man / cat3 / pcre.Z / pcre
Encoding:
Text File  |  1999-01-26  |  60.7 KB  |  1,586 lines

  1.  
  2.  
  3.  
  4.      PPPPCCCCRRRREEEE((((3333))))               UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV               PPPPCCCCRRRREEEE((((3333))))
  5.  
  6.  
  7.  
  8.      NNNNAAAAMMMMEEEE
  9.       pcre - Perl-compatible regular expressions.
  10.  
  11.      SSSSYYYYNNNNOOOOPPPPSSSSIIIISSSS
  12.       ####iiiinnnncccclllluuuuddddeeee <<<<ppppccccrrrreeee....hhhh>>>>
  13.  
  14.       ppppccccrrrreeee ****ppppccccrrrreeee____ccccoooommmmppppiiiilllleeee((((ccccoooonnnnsssstttt cccchhhhaaaarrrr    ****_p_a_t_t_e_r_n, int _o_p_t_i_o_n_s,
  15.            ccccoooonnnnsssstttt cccchhhhaaaarrrr ********_e_r_r_p_t_r, int    *_e_r_r_o_f_f_s_e_t);
  16.  
  17.       ppppccccrrrreeee____eeeexxxxttttrrrraaaa ****ppppccccrrrreeee____ssssttttuuuuddddyyyy((((ccccoooonnnnsssstttt ppppccccrrrreeee ****_c_o_d_e, int _o_p_t_i_o_n_s,
  18.            ccccoooonnnnsssstttt cccchhhhaaaarrrr ********_e_r_r_p_t_r);
  19.  
  20.       iiiinnnntttt ppppccccrrrreeee____eeeexxxxeeeecccc((((ccccoooonnnnsssstttt ppppccccrrrreeee ****_c_o_d_e, const    pcre_extra *_e_x_t_r_a,
  21.            ccccoooonnnnsssstttt cccchhhhaaaarrrr ****_s_u_b_j_e_c_t, int    _l_e_n_g_t_h,    int _o_p_t_i_o_n_s,
  22.            iiiinnnntttt ****_o_v_e_c_t_o_r, int _o_v_e_c_s_i_z_e);
  23.  
  24.       iiiinnnntttt ppppccccrrrreeee____iiiinnnnffffoooo((((ccccoooonnnnsssstttt ppppccccrrrreeee ****_c_o_d_e, int *_o_p_t_p_t_r, ****_f_i_r_s_t_c_h_a_r_p_t_r);
  25.  
  26.       cccchhhhaaaarrrr ****ppppccccrrrreeee____vvvveeeerrrrssssiiiioooonnnn((((vvvvooooiiiidddd))));;;;
  27.  
  28.       vvvvooooiiiidddd ****((((****ppppccccrrrreeee____mmmmaaaalllllllloooocccc))))((((ssssiiiizzzzeeee____tttt))));;;;
  29.  
  30.       vvvvooooiiiidddd ((((****ppppccccrrrreeee____ffffrrrreeeeeeee))))((((vvvvooooiiiidddd ****))));;;;
  31.  
  32.       uuuunnnnssssiiiiggggnnnneeeedddd cccchhhhaaaarrrr    ****ppppccccrrrreeee____ccccbbbbiiiittttssss[[[[111122228888]]]];;;;
  33.  
  34.       uuuunnnnssssiiiiggggnnnneeeedddd cccchhhhaaaarrrr    ****ppppccccrrrreeee____ccccttttyyyyppppeeeessss[[[[222255556666]]]];;;;
  35.  
  36.       uuuunnnnssssiiiiggggnnnneeeedddd cccchhhhaaaarrrr    ****ppppccccrrrreeee____ffffcccccccc[[[[222255556666]]]];;;;
  37.  
  38.       uuuunnnnssssiiiiggggnnnneeeedddd cccchhhhaaaarrrr    ****ppppccccrrrreeee____llllcccccccc[[[[222255556666]]]];;;;
  39.  
  40.  
  41.  
  42.  
  43.      DDDDEEEESSSSCCCCRRRRIIIIPPPPTTTTIIIIOOOONNNN
  44.       The PCRE library is a    set of functions that implement
  45.       regular expression pattern matching using the    same syntax
  46.       and semantics    as Perl    5, with    just a few differences (see
  47.       below). The current implementation corresponds to Perl
  48.       5.004.
  49.  
  50.       PCRE has its own native API, which is    described in this man
  51.       page.    There is also a    set of wrapper functions that
  52.       correspond to    the POSIX API. See ppppccccrrrreeeeppppoooossssiiiixxxx ((((3333)))).
  53.  
  54.       The three functions ppppccccrrrreeee____ccccoooommmmppppiiiilllleeee(((()))), ppppccccrrrreeee____ssssttttuuuuddddyyyy(((()))), and
  55.       ppppccccrrrreeee____eeeexxxxeeeecccc(((()))) are used for compiling and matching regular
  56.       expressions. The function ppppccccrrrreeee____iiiinnnnffffoooo(((())))    is used    to find    out
  57.       information about a compiled pattern,    while the function
  58.       ppppccccrrrreeee____vvvveeeerrrrssssiiiioooonnnn(((()))) returns a pointer to a    string containing the
  59.       version of PCRE and its date of release.
  60.  
  61.  
  62.  
  63.      Page 1                        (printed 12/10/98)
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.      PPPPCCCCRRRREEEE((((3333))))               UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV               PPPPCCCCRRRREEEE((((3333))))
  71.  
  72.  
  73.  
  74.       The global variables ppppccccrrrreeee____mmmmaaaalllllllloooocccc and ppppccccrrrreeee____ffffrrrreeeeeeee initially
  75.       contain the entry points of the standard mmmmaaaalllllllloooocccc(((()))) and    ffffrrrreeeeeeee(((())))
  76.       functions respectively. PCRE calls the memory    management
  77.       functions via    these variables, so a calling program can
  78.       replace them if it wishes to intercept the calls. This
  79.       should be done before    calling    any PCRE functions.
  80.  
  81.       The other global variables are character tables. They    are
  82.       initialized when PCRE    is compiled, from source that is
  83.       generated by reference to the    C character type functions,
  84.       but which the    maintainer of PCRE is free to modify. In
  85.       principle they could also be modified    at runtime. See    PCRE's
  86.       README file for more details.
  87.  
  88.  
  89.  
  90.      MMMMUUUULLLLTTTTIIII----TTTTHHHHRRRREEEEAAAADDDDIIIINNNNGGGG
  91.       The PCRE functions can be used in multi-threading
  92.       applications,    with the proviso that the character tables and
  93.       the memory management    functions pointed to by    ppppccccrrrreeee____mmmmaaaalllllllloooocccc
  94.       and ppppccccrrrreeee____ffffrrrreeeeeeee    will be    shared by all threads.
  95.  
  96.       The compiled form of a regular expression is not altered
  97.       during matching, so the same compiled    pattern    can safely be
  98.       used by several threads at once.
  99.  
  100.  
  101.  
  102.      CCCCOOOOMMMMPPPPIIIILLLLIIIINNNNGGGG AAAA PPPPAAAATTTTTTTTEEEERRRRNNNN
  103.       The function ppppccccrrrreeee____ccccoooommmmppppiiiilllleeee(((()))) is called    to compile a pattern
  104.       into an internal form. The pattern is    a C string terminated
  105.       by a binary zero, and    is passed in the argument _p_a_t_t_e_r_n. A
  106.       pointer to the compiled code block is    returned. The ppppccccrrrreeee
  107.       type is defined for this for convenience, but    in fact    ppppccccrrrreeee
  108.       is just a typedef for    vvvvooooiiiidddd, since the    contents of the    block
  109.       are not defined.
  110.  
  111.       The size of a    compiled pattern is roughly proportional to
  112.       the length of    the pattern string, except that    each character
  113.       class    (other than those containing just a single character,
  114.       negated or not) requires 33 bytes, and repeat    quantifiers
  115.       with a minimum greater than one or a bounded maximum cause
  116.       the relevant portions    of the compiled    pattern    to be
  117.       replicated.
  118.  
  119.       The _o_p_t_i_o_n_s argument contains    independent bits that affect
  120.       the compilation. It should be    zero if    no options are
  121.       required. Those options that are compabible with Perl    can
  122.       also be set at compile time from within the pattern (see the
  123.       detailed description of regular expressions below) and all
  124.       options except PCRE_EXTENDED,    PCRE_EXTRA and PCRE_UNGREEDY
  125.       can be set at    the time of matching.
  126.  
  127.  
  128.  
  129.      Page 2                        (printed 12/10/98)
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.      PPPPCCCCRRRREEEE((((3333))))               UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV               PPPPCCCCRRRREEEE((((3333))))
  137.  
  138.  
  139.  
  140.       If _e_r_r_p_t_r is NULL, ppppccccrrrreeee____ccccoooommmmppppiiiilllleeee(((()))) returns NULL immediately.
  141.       Otherwise, if    compilation of a pattern fails,    ppppccccrrrreeee____ccccoooommmmppppiiiilllleeee(((())))
  142.       returns NULL,    and sets the variable pointed to by _e_r_r_p_t_r to
  143.       point    to a textual error message.
  144.  
  145.       The offset from the start of the pattern to the character
  146.       where    the error was discovered is placed in the variable
  147.       pointed to by    _e_r_r_o_f_f_s_e_t, which must not be NULL. If it is,
  148.       an immediate error is    given.
  149.  
  150.       The following    option bits are    defined    in the header file:
  151.  
  152.         PCRE_ANCHORED
  153.  
  154.       If this bit is set, the pattern is forced to be "anchored",
  155.       that is, it is constrained to    match only at the start    of the
  156.       string which is being    searched (the "subject string"). This
  157.       effect can also be achieved by appropriate constructs    in the
  158.       pattern itself, which    is the only way    to do it in Perl.
  159.  
  160.         PCRE_CASELESS
  161.  
  162.       If this bit is set, letters in the pattern match both    upper
  163.       and lower case letters in any    subject    string.    It is
  164.       equivalent to    Perl's /i option.
  165.  
  166.         PCRE_DOLLAR_ENDONLY
  167.  
  168.       If this bit is set, a    dollar metacharacter in    the pattern
  169.       matches only at the end of the subject string. By default,
  170.       it also matches immediately before the final character if it
  171.       is a newline (but not    before any other newlines). The
  172.       PCRE_DOLLAR_ENDONLY option is    ignored    if PCRE_MULTILINE is
  173.       set. There is    no equivalent to this option in    Perl.
  174.  
  175.         PCRE_DOTALL
  176.  
  177.       If this bit is set, a    dot metacharater in the    pattern
  178.       matches all characters, including newlines. By default,
  179.       newlines are excluded. This option is    equivalent to Perl's
  180.       /s option. A negative    class such as [^a] always matches a
  181.       newline character, independent of the    setting    of this
  182.       option.
  183.  
  184.         PCRE_EXTENDED
  185.  
  186.       If this bit is set, whitespace characters in the pattern are
  187.       totally ignored except when escaped or inside    a character
  188.       class, and characters    between    an unescaped # outside a
  189.       character class and the next newline character, inclusive,
  190.       are also ignored. This is equivalent to Perl's /x option,
  191.       and makes it possible    to include comments inside complicated
  192.  
  193.  
  194.  
  195.      Page 3                        (printed 12/10/98)
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.      PPPPCCCCRRRREEEE((((3333))))               UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV               PPPPCCCCRRRREEEE((((3333))))
  203.  
  204.  
  205.  
  206.       patterns.
  207.  
  208.         PCRE_MULTILINE
  209.  
  210.       By default, PCRE treats the subject string as    consisting of
  211.       a single "line" of characters    (even if it actually contains
  212.       several newlines). The "start    of line" metacharacter (^)
  213.       matches only at the start of the string, while the "end of
  214.       line"    metacharacter ($) matches only at the end of the
  215.       string, or before a terminating newline. This    is the same as
  216.       Perl.
  217.  
  218.       When PCRE_MULTILINE it is set, the "start of line" and "end
  219.       of line" constructs match immediately    following or
  220.       immediately before any newline in the    subject    string,
  221.       respectively,    as well    as at the very start and end. This is
  222.       equivalent to    Perl's /m option. If there are no "\n"
  223.       characters in    a subject string, or no    occurrences of ^ or $
  224.       in a pattern,    setting    PCRE_MULTILINE has no effect.
  225.  
  226.         PCRE_EXTRA
  227.  
  228.       This option turns on additional functionality    of PCRE    that
  229.       is incompatible with Perl. Any backslash in a    pattern    that
  230.       is followed by a letter that has no special meaning causes
  231.       an error, thus reserving these combinations for future
  232.       expansion. By    default, as in Perl, a backslash followed by a
  233.       letter with no special meaning is treated as a literal.
  234.       There    are two    extra features currently provided, and both
  235.       are in some sense experimental additions that    are useful for
  236.       influencing the progress of a    match.
  237.  
  238.         (1)    The sequence \X    inserts    a Prolog-like "cut" into the
  239.       expression.
  240.  
  241.         (2)    Once a subpattern enclosed in (?>subpat) brackets has
  242.       matched,
  243.         backtracking never goes    back into the pattern.
  244.  
  245.       See below for    further    details    of both    of these. PCRE_EXTRA
  246.       can be set by    a (?X) option setting within the pattern, but
  247.       this must precede anything in    the pattern which relies on
  248.       its being set.
  249.  
  250.         PCRE_UNGREEDY
  251.  
  252.       This option inverts the "greediness" of the quantifiers so
  253.       that they are    not greedy by default, but become greedy if
  254.       followed by "?". It is not compatible    with Perl. It can also
  255.       be set by a (?U) option setting within the pattern.
  256.  
  257.  
  258.  
  259.  
  260.  
  261.      Page 4                        (printed 12/10/98)
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.      PPPPCCCCRRRREEEE((((3333))))               UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV               PPPPCCCCRRRREEEE((((3333))))
  269.  
  270.  
  271.  
  272.      SSSSTTTTUUUUDDDDYYYYIIIINNNNGGGG AAAA    PPPPAAAATTTTTTTTEEEERRRRNNNN
  273.       When a pattern is going to be    used several times, it is
  274.       worth    spending more time analyzing it    in order to speed up
  275.       the time taken for matching. The function ppppccccrrrreeee____ssssttttuuuuddddyyyy(((()))) takes
  276.       a pointer to a compiled pattern as its first argument, and
  277.       returns a pointer to a ppppccccrrrreeee____eeeexxxxttttrrrraaaa block (another vvvvooooiiiidddd
  278.       typedef) containing additional information about the
  279.       pattern; this    can be passed to ppppccccrrrreeee____eeeexxxxeeeecccc(((()))). If no additional
  280.       information is available, NULL is returned.
  281.  
  282.       The second argument contains option bits. The    only one
  283.       currently supported is PCRE_CASELESS.    It forces the studying
  284.       to be    done in    a caseless manner, even    if the original
  285.       pattern was compiled without PCRE_CASELESS. When the result
  286.       of ppppccccrrrreeee____ssssttttuuuuddddyyyy(((()))) is passed to ppppccccrrrreeee____eeeexxxxeeeecccc(((()))), it is used only if
  287.       its caseless state is    the same as that of the    matching
  288.       process. A pattern that is compiled without PCRE_CASELESS
  289.       can be studied with and without PCRE_CASELESS, and the
  290.       appropriate data passed to ppppccccrrrreeee____eeeexxxxeeeecccc(((()))) with and without the
  291.       PCRE_CASELESS    flag.
  292.  
  293.       The third argument for ppppccccrrrreeee____ssssttttuuuuddddyyyy(((()))) is a pointer to an error
  294.       message. If studying succeeds    (even if no data is returned),
  295.       the variable it points to is set to NULL. Otherwise it
  296.       points to a textual error message.
  297.  
  298.       At present, studying a pattern is useful only    for non-
  299.       anchored patterns that do not    have a single fixed starting
  300.       character. A bitmap of possible starting characters is
  301.       created.
  302.  
  303.  
  304.  
  305.      MMMMAAAATTTTCCCCHHHHIIIINNNNGGGG AAAA    PPPPAAAATTTTTTTTEEEERRRRNNNN
  306.       The function ppppccccrrrreeee____eeeexxxxeeeecccc(((()))) is called to    match a    subject    string
  307.       against a pre-compiled pattern, which    is passed in the _c_o_d_e
  308.       argument. If the pattern has been studied, the result    of the
  309.       study    should be passed in the    _e_x_t_r_a argument.    Otherwise this
  310.       must be NULL.
  311.  
  312.       The subject string is    passed as a pointer in _s_u_b_j_e_c_t and a
  313.       length in _l_e_n_g_t_h. Unlike the pattern string, it may contain
  314.       binary zero characters.
  315.  
  316.       The options PCRE_ANCHORED, PCRE_CASELESS,
  317.       PCRE_DOLLAR_ENDONLY, PCRE_DOTALL, and    PCRE_MULTILINE can be
  318.       passed in the    _o_p_t_i_o_n_s    argument, whose    unused bits must be
  319.       zero.    However, if a pattern is compiled with any of these
  320.       options, they    cannot be unset    when it    is obeyed.
  321.  
  322.       There    are also two further options that can be set only at
  323.       matching time:
  324.  
  325.  
  326.  
  327.      Page 5                        (printed 12/10/98)
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.      PPPPCCCCRRRREEEE((((3333))))               UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV               PPPPCCCCRRRREEEE((((3333))))
  335.  
  336.  
  337.  
  338.         PCRE_NOTBOL
  339.  
  340.       The first character of the string is not the beginning of a
  341.       line,    so the circumflex metacharacter    should not match
  342.       before it. Setting this without PCRE_MULTILINE (at either
  343.       compile or match time) causes    circumflex never to match.
  344.  
  345.         PCRE_NOTEOL
  346.  
  347.       The end of the string    is not the end of a line, so the
  348.       dollar metacharacter should not match    it. Setting this
  349.       without PCRE_MULTILINE (at either compile or match time)
  350.       causes dollar    never to match.
  351.  
  352.       In general, a    pattern    matches    a certain portion of the
  353.       subject, and in addition, further substrings from the
  354.       subject may be picked    out by parts of    the pattern. Following
  355.       the usage in Jeffrey Friedl's    book, this is called
  356.       "capturing" in what follows, and the phrase "capturing
  357.       subpattern" is used for a fragment of    a pattern that picks
  358.       out a    substring. PCRE    supports several other kinds of
  359.       parenthesized    subpattern that    do not cause substrings    to be
  360.       captured.
  361.  
  362.       Captured substrings are returned to the caller via a vector
  363.       of integer offsets whose address is passed in    _o_v_e_c_t_o_r. The
  364.       number of elements in    the vector is passed in    _o_v_e_c_s_i_z_e. This
  365.       should always    be an even number, because the elements    are
  366.       used in pairs. If an odd number is passed, it    is rounded
  367.       down.
  368.  
  369.       The first element of a pair is set to    the offset of the
  370.       first    character in a substring, and the second is set    to the
  371.       offset of the    first character    after the end of a substring.
  372.       The first pair, _o_v_e_c_t_o_r[_0] and _o_v_e_c_t_o_r[_1], identify the
  373.       portion of the subject string    matched    by the entire pattern.
  374.       The next pair    is used    for the    first capturing    subpattern,
  375.       and so on. The value returned    by ppppccccrrrreeee____eeeexxxxeeeecccc(((()))) is the number
  376.       of pairs that    have been set. If there    are no capturing
  377.       subpatterns, the return value    from a successful match    is 1,
  378.       indicating that just the first pair of offsets has been set.
  379.  
  380.       It is    possible for an    capturing subpattern number _n+_1    to
  381.       match    some part of the subject when subpattern _n has not
  382.       been used at all. For    example, if the    string "abc" is
  383.       matched against the pattern "(a|(z))(bc)", subpatterns 1 and
  384.       3 are    matched, but 2 is not. When this happens, both offset
  385.       values corresponding to the unused subpattern    are set    to -1.
  386.  
  387.       If a capturing subpattern is matched repeatedly, it is the
  388.       last portion of the string that it matched that gets
  389.       returned.
  390.  
  391.  
  392.  
  393.      Page 6                        (printed 12/10/98)
  394.  
  395.  
  396.  
  397.  
  398.  
  399.  
  400.      PPPPCCCCRRRREEEE((((3333))))               UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV               PPPPCCCCRRRREEEE((((3333))))
  401.  
  402.  
  403.  
  404.       If the vector    is too small to    hold all the captured
  405.       substrings, it is used as far    as possible, and the function
  406.       returns a value of zero. In particular, if the substring
  407.       offsets are not of interest, ppppccccrrrreeee____eeeexxxxeeeecccc(((()))) may be called with
  408.       _o_v_e_c_t_o_r passed as NULL and _o_v_e_c_s_i_z_e as zero. However,    if the
  409.       pattern contains back    references and the _o_v_e_c_t_o_r isn't big
  410.       enough to remember the related substrings, PCRE has to get
  411.       additional memory for    use during matching. Thus it is
  412.       usually advisable to supply an _o_v_e_c_t_o_r.
  413.  
  414.       Note that ppppccccrrrreeee____iiiinnnnffffoooo(((())))    can be used to find out    how many
  415.       capturing subpatterns    there are in a compiled    pattern.
  416.  
  417.       If ppppccccrrrreeee____eeeexxxxeeeecccc(((()))) fails,    it returns a negative number. The
  418.       following are    defined    in the header file:
  419.  
  420.         PCRE_ERROR_NOMATCH          (-1)
  421.  
  422.       The subject string did not match the pattern.
  423.  
  424.         PCRE_ERROR_BADREF          (-2)
  425.  
  426.       There    was a back-reference in    the pattern to a capturing
  427.       subpattern that had not previously been set.
  428.  
  429.         PCRE_ERROR_NULL          (-3)
  430.  
  431.       Either _c_o_d_e or _s_u_b_j_e_c_t was passed as NULL, or    _o_v_e_c_t_o_r    was
  432.       NULL and _o_v_e_c_s_i_z_e was    not zero.
  433.  
  434.         PCRE_ERROR_BADOPTION      (-4)
  435.  
  436.       An unrecognized bit was set in the _o_p_t_i_o_n_s argument.
  437.  
  438.         PCRE_ERROR_BADMAGIC          (-5)
  439.  
  440.       PCRE stores a    4-byte "magic number" at the start of the
  441.       compiled code, to catch the case when    it is passed a junk
  442.       pointer. This    is the error it    gives when the magic number
  443.       isn't    present.
  444.  
  445.         PCRE_ERROR_UNKNOWN_NODE   (-6)
  446.  
  447.       While    running    the pattern match, an unknown item was
  448.       encountered in the compiled pattern. This error could    be
  449.       caused by a bug in PCRE or by    overwriting of the compiled
  450.       pattern.
  451.  
  452.         PCRE_ERROR_NOMEMORY          (-7)
  453.  
  454.       If a pattern contains    back references, but the _o_v_e_c_t_o_r that
  455.       is passed to ppppccccrrrreeee____eeeexxxxeeeecccc(((()))) is not big enough to    remember the
  456.  
  457.  
  458.  
  459.      Page 7                        (printed 12/10/98)
  460.  
  461.  
  462.  
  463.  
  464.  
  465.  
  466.      PPPPCCCCRRRREEEE((((3333))))               UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV               PPPPCCCCRRRREEEE((((3333))))
  467.  
  468.  
  469.  
  470.       referenced substrings, PCRE gets a block of memory at    the
  471.       start    of matching to use for this purpose. If    the call via
  472.       ppppccccrrrreeee____mmmmaaaalllllllloooocccc(((())))    fails, this error is given. The    memory is
  473.       freed    at the end of matching.
  474.  
  475.  
  476.  
  477.      IIIINNNNFFFFOOOORRRRMMMMAAAATTTTIIIIOOOONNNN AAAABBBBOOOOUUUUTTTT AAAA PPPPAAAATTTTTTTTEEEERRRRNNNN
  478.       The ppppccccrrrreeee____iiiinnnnffffoooo(((()))) function returns information about a
  479.       compiled pattern.  Its yield is the number of    capturing
  480.       subpatterns, or one of the following negative    numbers:
  481.  
  482.         PCRE_ERROR_NULL      the argument _c_o_d_e was    NULL
  483.         PCRE_ERROR_BADMAGIC      the "magic number" was not found
  484.  
  485.       If the _o_p_t_p_t_r    argument is not    NULL, a    copy of    the options
  486.       with which the pattern was compiled is placed    in the integer
  487.       it points to.
  488.  
  489.       If the _f_i_r_s_t_c_h_a_r_p_t_r argument is not NULL, is is used to pass
  490.       back information about the first character of    any matched
  491.       string. If there is a    fixed first character, e.g. from a
  492.       pattern such as (cat|cow|coyote), then it is returned    in the
  493.       integer pointed to by    _f_i_r_s_t_c_h_a_r_p_t_r. Otherwise, if the
  494.       pattern was compiled with the    PCRE_MULTILINE option, and
  495.       every    branch started with "^", then -1 is returned,
  496.       indicating that the pattern will match at the    start of a
  497.       subject string or after any "\n" within the string.
  498.       Otherwise -2 is returned.
  499.  
  500.  
  501.  
  502.      LLLLIIIIMMMMIIIITTTTAAAATTTTIIIIOOOONNNNSSSS
  503.       There    are some size limitations in PCRE but it is hoped that
  504.       they will never in practice be relevant.  The    maximum    length
  505.       of a compiled    pattern    is 65539 (sic) bytes.  All values in
  506.       repeating quantifiers    must be    less than 65536.  The maximum
  507.       number of capturing subpatterns is 99.  The maximum number
  508.       of all parenthesized subpatterns, including capturing
  509.       subpatterns and assertions, is 200.
  510.  
  511.       The maximum length of    a subject string is the    largest
  512.       positive number that an integer variable can hold. However,
  513.       PCRE uses recursion to handle    subpatterns and    indefinite
  514.       repetition. This means that the available stack space    may
  515.       limit    the size of a subject string that can be processed by
  516.       certain patterns.
  517.  
  518.  
  519.  
  520.      DDDDIIIIFFFFFFFFEEEERRRREEEENNNNCCCCEEEESSSS FFFFRRRROOOOMMMM PPPPEEEERRRRLLLL
  521.       The differences described here are with respect to Perl
  522.  
  523.  
  524.  
  525.      Page 8                        (printed 12/10/98)
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.      PPPPCCCCRRRREEEE((((3333))))               UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV               PPPPCCCCRRRREEEE((((3333))))
  533.  
  534.  
  535.  
  536.       5.004.
  537.  
  538.       1. By    default, a whitespace character    is any character that
  539.       the C    library    function iiiissssssssppppaaaacccceeee(((()))) recognizes, though it is
  540.       possible to compile PCRE with    alternative character type
  541.       tables. Normally iiiissssssssppppaaaacccceeee(((()))) matches space, formfeed, newline,
  542.       carriage return, horizontal tab, and vertical    tab. Perl 5 no
  543.       longer includes vertical tab in its set of whitespace
  544.       characters. The \v escape that was in    the Perl documentation
  545.       for a    long time was never in fact recognized.    However, the
  546.       character itself was treated as whitespace at    least up to
  547.       5.002. In 5.004 it does not match \s.
  548.  
  549.       2. PCRE does not allow repeat    quantifiers on lookahead
  550.       assertions. Perl permits them, but they do not mean what you
  551.       might    think. For example, "(?!a){3}" does not    assert that
  552.       the next three characters are    not "a". It just asserts that
  553.       the next character is    not "a"    three times.
  554.  
  555.       3. Capturing subpatterns that    occur inside negative
  556.       lookahead assertions are counted, but    their entries in the
  557.       offsets vector are never set.    Perl sets its numerical
  558.       variables from any such patterns that    are matched before the
  559.       assertion fails to match something (thereby succeeding), but
  560.       only if the negative lookahead assertion contains just one
  561.       branch.
  562.  
  563.       4. Though binary zero    characters are supported in the
  564.       subject string, they are not allowed in a pattern string
  565.       because it is    passed as a normal C string, terminated    by
  566.       zero.    The escape sequence "\0" can be    used in    the pattern to
  567.       represent a binary zero.
  568.  
  569.       5. The following Perl    escape sequences are not supported:
  570.       \l, \u, \L, \U, \E, \Q. In fact these    are implemented    by
  571.       Perl's general string-handling and are not part of its
  572.       pattern matching engine.
  573.  
  574.       6. The Perl \G assertion is not supported as it is not
  575.       relevant to single pattern matches.
  576.  
  577.       7. If    a backreference    can never be matched, PCRE diagnoses
  578.       an error. In a case like
  579.  
  580.         /(123)\2/
  581.  
  582.       the error occurs at compile time. Perl gives no compile time
  583.       error; version 5.004 either always fails to match, or    gives
  584.       a segmentation fault at runtime.  In more complicated    cases
  585.       such as
  586.  
  587.         /(1)(2)(3)(4)(5)(6)(7)(8)(9)(10\10)/
  588.  
  589.  
  590.  
  591.      Page 9                        (printed 12/10/98)
  592.  
  593.  
  594.  
  595.  
  596.  
  597.  
  598.      PPPPCCCCRRRREEEE((((3333))))               UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV               PPPPCCCCRRRREEEE((((3333))))
  599.  
  600.  
  601.  
  602.       PCRE returns PCRE_ERROR_BADREF at run    time. Perl always
  603.       fails    to match.
  604.  
  605.       8. PCRE provides some    extensions to the Perl regular
  606.       expression facilities:
  607.  
  608.       (a) If PCRE_DOLLAR_ENDONLY is    set and    PCRE_MULTILINE is not
  609.       set, the $ meta- character matches only at the very end of
  610.       the string.
  611.  
  612.       (b) If PCRE_EXTRA is set, the    \X assertion (a    Prolog-like
  613.       "cut") is recognized,    and a backslash    followed by a letter
  614.       with no special meaning is faulted. There is also a new kind
  615.       of parenthesized subpattern starting with (?>    which has a
  616.       block    on backtracking    into it    once it    has matched.
  617.  
  618.       (c) If PCRE_UNGREEDY is set, the greediness of the
  619.       repetition quantifiers is inverted, that is, by default they
  620.       are not greedy, but if followed by a question    mark they are.
  621.  
  622.  
  623.  
  624.      RRRREEEEGGGGUUUULLLLAAAARRRR EEEEXXXXPPPPRRRREEEESSSSSSSSIIIIOOOONNNN    DDDDEEEETTTTAAAAIIIILLLLSSSS
  625.       The syntax and semantics of the regular expressions
  626.       supported by PCRE are    described below. Regular expressions
  627.       are also described in    the Perl documentation and in a    number
  628.       of other books, some of which    have copious examples. Jeffrey
  629.       Friedl's "Mastering Regular Expressions", published by
  630.       O'Reilly (ISBN 1-56592-257-3), covers    them in    great detail.
  631.       The description here is intended as reference    documentation.
  632.  
  633.       A regular expression is a pattern that is matched against a
  634.       subject string from left to right. Most characters stand for
  635.       themselves in    a pattern, and match the corresponding
  636.       characters in    the subject. As    a trivial example, the pattern
  637.  
  638.         The    quick brown fox
  639.  
  640.       matches a portion of a subject string    that is    identical to
  641.       itself. The power of regular expressions comes from the
  642.       ability to include alternatives and repetitions in the
  643.       pattern. These are encoded in    the pattern by the use of
  644.       _m_e_t_a-_c_h_a_r_a_c_t_e_r_s, which do not    stand for themselves but
  645.       instead are interpreted in some special way.
  646.  
  647.       There    are two    different sets of meta-characters: those that
  648.       are recognized anywhere in the pattern except    within square
  649.       brackets, and    those that are recognized in square brackets.
  650.       Outside square brackets, the meta-characters are as follows:
  651.  
  652.         \       general escape character with several uses
  653.         ^       assert start    of subject (or line, in    multiline
  654.  
  655.  
  656.  
  657.      Page 10                        (printed 12/10/98)
  658.  
  659.  
  660.  
  661.  
  662.  
  663.  
  664.      PPPPCCCCRRRREEEE((((3333))))               UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV               PPPPCCCCRRRREEEE((((3333))))
  665.  
  666.  
  667.  
  668.       mode)
  669.         $       assert end of subject (or line, in multiline    mode)
  670.         .       match any character except newline (by default)
  671.         [       start character class definition
  672.         |       start of alternative    branch
  673.         (       start subpattern
  674.         )       end subpattern
  675.         ?       extends the meaning of (
  676.            also    0 or 1 quantifier
  677.            also    quantifier minimizer
  678.         *       0 or    more quantifier
  679.         +       1 or    more quantifier
  680.         {       start min/max quantifier
  681.  
  682.       Part of a pattern that is in square brackets is called a
  683.       "character class". In    a character class the only meta-
  684.       characters are:
  685.  
  686.         \       general escape character
  687.         ^       negate the class, but only if the first character
  688.         -       indicates character range
  689.         ]       terminates the character class
  690.  
  691.       The following    sections describe the use of each of the
  692.       meta-characters.
  693.  
  694.  
  695.  
  696.      BBBBAAAACCCCKKKKSSSSLLLLAAAASSSSHHHH
  697.       The backslash    character has several uses. Firstly, if    it is
  698.       followed by a    non-alphameric character, it takes away    any
  699.       special meaning that character may have. This    use of
  700.       backslash as an escape character applies both    inside and
  701.       outside character classes.
  702.  
  703.       For example, if you want to match a "*" character, you write
  704.       "\*" in the pattern. This applies whether or not the
  705.       following character would otherwise be interpreted as    a
  706.       meta-character, so it    is always safe to precede a non-
  707.       alphameric with "\" to specify that it stands    for itself. In
  708.       particular, if you want to match a backslash,    you write
  709.       "\\".
  710.  
  711.       If a pattern is compiled with    the PCRE_EXTENDED option,
  712.       whitespace in    the pattern and    characters between a "#"
  713.       outside a character class and    the next newline character are
  714.       ignored. An escaping backslash can be    used to    include    a
  715.       whitespace or    "#" character as part of the pattern.
  716.  
  717.       A second use of backslash provides a way of encoding non-
  718.       printing characters in patterns in a visible manner. There
  719.       is no    restriction on the appearance of non-printing
  720.  
  721.  
  722.  
  723.      Page 11                        (printed 12/10/98)
  724.  
  725.  
  726.  
  727.  
  728.  
  729.  
  730.      PPPPCCCCRRRREEEE((((3333))))               UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV               PPPPCCCCRRRREEEE((((3333))))
  731.  
  732.  
  733.  
  734.       characters, apart from the binary zero that terminates a
  735.       pattern, but when a pattern is being prepared    by text
  736.       editing, it is usually easier    to use one of the following
  737.       escape sequences than    the binary character it    represents:
  738.  
  739.         \a       alarm, that is, the BEL character (hex 07)
  740.         \cx       "control-x",    where x    is any character
  741.         \e       escape (hex 1B)
  742.         \f       formfeed (hex 0C)
  743.         \n       newline (hex    0A)
  744.         \r       carriage return (hex    0D)
  745.         \t       tab (hex 09)
  746.         \xhh   character with hex code hh
  747.         \ddd   character with octal    code ddd or backreference
  748.  
  749.       The precise effect of    "\cx" is as follows: if    "x" is a lower
  750.       case letter, it is converted to upper    case. Then bit 6 of
  751.       the character    (hex 40) is inverted.  Thus "\cz" becomes hex
  752.       1A, but "\c{"    becomes    hex 3B,    while "\c;" becomes hex    7B.
  753.  
  754.       After    "\x", up to two    hexadecimal digits are read (letters
  755.       can be in upper or lower case).
  756.  
  757.       After    "\0" up    to two further octal digits are    read. In both
  758.       cases, if there are fewer than two digits, just those    that
  759.       are present are used.    Thus the sequence "\0\x\07" specifies
  760.       two binary zeros followed by a BEL character.     Make sure you
  761.       supply two digits if the character that follows could
  762.       otherwise be taken as    another    digit.
  763.  
  764.       The handling of a backslash followed by a digit other    than 0
  765.       is complicated.  Outside a character class, PCRE reads it
  766.       and any following digits as a    decimal    number.    If the number
  767.       is less than 10, or if there have been at least that many
  768.       previous capturing left parentheses in the expression, the
  769.       entire sequence is taken as a    _b_a_c_k _r_e_f_e_r_e_n_c_e.    A description
  770.       of how this works is given later, following the discussion
  771.       of parenthesized subpatterns.
  772.  
  773.       Inside a character class, or if the decimal number is
  774.       greater than 9 and there have    not been that many capturing
  775.       subpatterns, PCRE re-reads up    to three octal digits
  776.       following the    backslash, and generates a single byte from
  777.       the least significant    8 bits of the value. Any subsequent
  778.       digits stand for themselves.    For example:
  779.  
  780.         \040   is another way of writing a space
  781.         \40       is the same,    provided there are fewer than 40
  782.               previous capturing subpatterns
  783.         \7       is always a back reference
  784.         \11       might be a back reference, or another way of
  785.               writing a    tab
  786.  
  787.  
  788.  
  789.      Page 12                        (printed 12/10/98)
  790.  
  791.  
  792.  
  793.  
  794.  
  795.  
  796.      PPPPCCCCRRRREEEE((((3333))))               UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV               PPPPCCCCRRRREEEE((((3333))))
  797.  
  798.  
  799.  
  800.          11      is always a tab
  801.         \0113  is a    tab followed by    the character "3"
  802.         \113   is the character with octal code 113    (since there
  803.               can be no    more than 99 back references)
  804.         \377   is a    byte consisting    entirely of 1 bits
  805.         \81       is either a back reference, or a binary zero
  806.               followed by the two characters "8" and "1"
  807.  
  808.       Note that octal values of 100    or greater must    not be
  809.       introduced by    a leading zero,    because    no more    than three
  810.       octal    digits are ever    read.
  811.  
  812.       All the sequences that define    a single byte value can    be
  813.       used both inside and outside character classes. In addition,
  814.       inside a character class, the    sequence "\b" is interpreted
  815.       as the backspace character (hex 08). Outside a character
  816.       class    it has a different meaning (see    below).
  817.  
  818.       The third use    of backslash is    for specifying generic
  819.       character types:
  820.  
  821.         \d       any decimal digit
  822.         \D       any character that is not a decimal digit
  823.         \s       any whitespace character
  824.         \S       any character that is not a whitespace character
  825.         \w       any "word" character
  826.         \W       any "non-word" character
  827.  
  828.       Each pair of escape sequences    partitions the complete    set of
  829.       characters into two disjoint sets. Any given character
  830.       matches one, and only    one, of    each pair.
  831.  
  832.       A "word" character is    any letter or digit or the underscore
  833.       character, that is, any character which can be part of a
  834.       Perl "word". These character type sequences can appear both
  835.       inside and outside character classes.    They each match    one
  836.       character of the appropriate type. If    the current matching
  837.       point    is at the end of the subject string, all of them fail,
  838.       since    there is no character to match.
  839.  
  840.       The fourth use of backslash is for certain assertions. An
  841.       assertion specifies a    condition that has to be met at    a
  842.       particular point in a    match, without consuming any
  843.       characters from the subject string. The backslashed
  844.       assertions are
  845.  
  846.         \b       word    boundary
  847.         \B       not a word boundary
  848.         \A       start of subject (independent of multiline mode)
  849.         \Z       end of subject (independent of multiline mode)
  850.  
  851.       Assertions may not appear in character classes (but note
  852.  
  853.  
  854.  
  855.      Page 13                        (printed 12/10/98)
  856.  
  857.  
  858.  
  859.  
  860.  
  861.  
  862.      PPPPCCCCRRRREEEE((((3333))))               UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV               PPPPCCCCRRRREEEE((((3333))))
  863.  
  864.  
  865.  
  866.       that "\b" has    a different meaning, namely the    backspace
  867.       character, inside a character    class).
  868.  
  869.       A word boundary is a position    in the subject string where
  870.       the current character    and the    previous character do not both
  871.       match    "\w" or    "\W" (i.e. one matches "\w" and    the other
  872.       matches "\W"), or the    start or end of    the string if the
  873.       first    or last    character matches "\w",    respectively. More
  874.       complicated assertions are also supported (see below).
  875.  
  876.       The "\A" and "\Z" assertions differ from the traditional "^"
  877.       and "$" (described below) in that they only ever match at
  878.       the very start and end of the    subject    string,    respectively,
  879.       whatever options are set.
  880.  
  881.       When the PCRE_EXTRA flag is set on a call to ppppccccrrrreeee____ccccoooommmmppppiiiilllleeee(((()))),
  882.       the additional assertion \X, which has no equivalent in
  883.       Perl,    is recognized.    This operates like the "cut" operation
  884.       in Prolog: it    prevents the matching operation    from
  885.       backtracking past it.    For example, if    the expression
  886.  
  887.         .*/foo
  888.  
  889.       is matched against the string    "/this/string/is/not" then
  890.       after    the greedy .*  has swallowed the whole string, PCRE
  891.       keeps    backtracking all the way to the    beginning before
  892.       failing. If, on the other hand, the expression is
  893.  
  894.         .*/\Xfoo
  895.  
  896.       then once it has discovered that "/not" is not "/foo",
  897.       backtracking ceases, and the match fails. See    also the
  898.       section on "once-only" subpatterns below.
  899.  
  900.  
  901.  
  902.  
  903.      CCCCIIIIRRRRCCCCUUUUMMMMFFFFLLLLEEEEXXXX    AAAANNNNDDDD DDDDOOOOLLLLLLLLAAAARRRR
  904.       Outside a character class, the circumflex character is an
  905.       assertion which is true only if the current matching point
  906.       is at    the start of the subject string, in the    default
  907.       matching mode. Inside    a character class, circumflex has an
  908.       entirely different meaning (see below).
  909.  
  910.       Circumflex need not be the first character of    the pattern if
  911.       a number of alternatives are involved, but it    should be the
  912.       first    thing in each alternative in which it appears if the
  913.       pattern is ever to match that    branch.    If all possible
  914.       alternatives start with a circumflex,    that is, if the
  915.       pattern is constrained to match only at the start of the
  916.       subject, it is said to be an "anchored" pattern. (There are
  917.       also other constructs    that can cause a pattern to be
  918.  
  919.  
  920.  
  921.      Page 14                        (printed 12/10/98)
  922.  
  923.  
  924.  
  925.  
  926.  
  927.  
  928.      PPPPCCCCRRRREEEE((((3333))))               UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV               PPPPCCCCRRRREEEE((((3333))))
  929.  
  930.  
  931.  
  932.       anchored.)
  933.  
  934.       A dollar character is    an assertion which is true only    if the
  935.       current matching point is at the end of the subject string,
  936.       or immediately before    a newline character that is the    last
  937.       character in the string (by default).    Dollar need not    be the
  938.       last character of the    pattern    if a number of alternatives
  939.       are involved,    but it should be the last item in any branch
  940.       in which it appears.    Dollar has no special meaning in a
  941.       character class.
  942.  
  943.       The meaning of dollar    can be changed so that it matches only
  944.       at the very end of the string, by setting the
  945.       PCRE_DOLLAR_ENDONLY option at    compile    or matching time.
  946.  
  947.       The meanings of the circumflex and dollar characters are
  948.       changed if the PCRE_MULTILINE    option is set at compile or
  949.       matching time. When this is the case,    they match immediately
  950.       after    and immediately    before an internal "\n"    character,
  951.       respectively,    in addition to matching    at the start and end
  952.       of the subject string. For example, the pattern /^abc$/
  953.       matches the subject string "def\nabc"    in multiline mode, but
  954.       not otherwise. Consequently, patterns    that are anchored in
  955.       single line mode because all branches    start with "^" are not
  956.       anchored in multiline    mode. The PCRE_DOLLAR_ENDONLY option
  957.       is ignored if    PCRE_MULTILINE is set.
  958.  
  959.       Note that the    sequences "\A" and "\Z"    can be used to match
  960.       the start and    end of the subject in both modes, and if all
  961.       branches of a    pattern    start with "\A"    is it always anchored.
  962.  
  963.  
  964.  
  965.      FFFFUUUULLLLLLLL SSSSTTTTOOOOPPPP ((((PPPPEEEERRRRIIIIOOOODDDD,,,,    DDDDOOOOTTTT))))
  966.       Outside a character class, a dot in the pattern matches any
  967.       one character    in the subject,    including a non-printing
  968.       character, but not (by default) newline.  If the PCRE_DOTALL
  969.       option is set, then dots match newlines as well. The
  970.       handling of dot is entirely independent of the handling of
  971.       circumflex and dollar, the only relationship being that they
  972.       both involve newline characters.  Dot    has no special meaning
  973.       in a character class.
  974.  
  975.  
  976.  
  977.      SSSSQQQQUUUUAAAARRRREEEE BBBBRRRRAAAACCCCKKKKEEEETTTTSSSS
  978.       An opening square bracket introduces a character class,
  979.       terminated by    a closing square bracket. A closing square
  980.       bracket on its own is    not special. If    a closing square
  981.       bracket is required as a member of the class,    it should be
  982.       the first data character in the class    (after an initial
  983.       circumflex, if present) or escaped with \.
  984.  
  985.  
  986.  
  987.      Page 15                        (printed 12/10/98)
  988.  
  989.  
  990.  
  991.  
  992.  
  993.  
  994.      PPPPCCCCRRRREEEE((((3333))))               UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV               PPPPCCCCRRRREEEE((((3333))))
  995.  
  996.  
  997.  
  998.       A character class matches a single character in the subject;
  999.       the character    must be    in the set of characters defined by
  1000.       the class, unless the    first character    in the class is    a
  1001.       circumflex, in which case the    subject    character must not be
  1002.       in the set defined by    the class. If a    circumflex is actually
  1003.       required as a    member of the class, ensure it is not the
  1004.       first    character, or escape it    with \.
  1005.  
  1006.       For example, the character class [aeiou] matches any lower
  1007.       case vowel, while [^aeiou] matches any character that    is not
  1008.       a lower case vowel. Note that    a circumflex is    just a
  1009.       convenient notation for specifying the characters which are
  1010.       in the class by enumerating those that are not. It is    not an
  1011.       assertion: it    still consumes a character from    the subject
  1012.       string, and fails if the current pointer is at the end of
  1013.       the string.
  1014.  
  1015.       The newline character    is never treated in any    special    way in
  1016.       character classes, whatever the setting of the PCRE_DOTALL
  1017.       or PCRE_MULTILINE options is.    A class    such as    [^a] will
  1018.       always match a newline.
  1019.  
  1020.       The minus (hyphen) character can be used to specify a    range
  1021.       of characters    in a character class. For example, [d-m]
  1022.       matches any letter between d and m, inclusive. If a minus
  1023.       character is required    in a class, it must be escaped with \
  1024.       or appear in a position where    it cannot be interpreted as
  1025.       indicating a range, typically    as the first or    last character
  1026.       in the class.    It is not possible to have the character "]"
  1027.       as the end character of a range, since a sequence such as
  1028.       [w-] is interpreted as a class of two    characters. The    octal
  1029.       or hexadecimal representation    of "]" can, however, be    used
  1030.       to end a range.
  1031.  
  1032.       Ranges operate in ASCII collating sequence. They can also be
  1033.       used for characters specified    numerically, for example
  1034.       [\000-\037]. If a range such as [W-c]    is used    when
  1035.       PCRE_CASELESS    is set,    it matches the letters involved    in
  1036.       either case.
  1037.  
  1038.       The character    types \d, \D, \s, \S, \w, and \W may also
  1039.       appear in a character    class, and add the characters that
  1040.       they match to    the class. For example,    the class [^\W_]
  1041.       matches any letter or    digit.
  1042.  
  1043.       All non-alphameric characters    other than \, -, ^ (at the
  1044.       start) and the terminating ] are non-special in character
  1045.       classes, but it does no harm if they are escaped.
  1046.  
  1047.  
  1048.  
  1049.      VVVVEEEERRRRTTTTIIIICCCCAAAALLLL BBBBAAAARRRR
  1050.  
  1051.  
  1052.  
  1053.      PPPPaaaaggggeeee 11116666                        ((((pppprrrriiiinnnntttteeeedddd 11112222////11110000////99998888))))
  1054.  
  1055.  
  1056.  
  1057.  
  1058.  
  1059.  
  1060.      PPPPCCCCRRRREEEE((((3333))))               UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV               PPPPCCCCRRRREEEE((((3333))))
  1061.  
  1062.  
  1063.  
  1064.       Vertical bar characters are used to separate alternative
  1065.       patterns. The    matching process tries all the alternatives in
  1066.       turn.    For example, the pattern
  1067.  
  1068.         gilbert|sullivan
  1069.  
  1070.       matches either "gilbert" or "sullivan". Any number of
  1071.       alternatives can be used, and    an empty alternative is
  1072.       permitted (matching the empty    string).
  1073.  
  1074.  
  1075.  
  1076.      SSSSUUUUBBBBPPPPAAAATTTTTTTTEEEERRRRNNNNSSSS
  1077.       Subpatterns are delimited by parentheses (round brackets),
  1078.       which    can be nested.    Marking    part of    a pattern as a
  1079.       subpattern does two things:
  1080.  
  1081.       1. It    localizes a set    of alternatives. For example, the
  1082.       pattern
  1083.  
  1084.         cat(aract|erpillar|)
  1085.  
  1086.       matches one of the words "cat", "cataract", or
  1087.       "caterpillar". Without the parentheses, it would match
  1088.       "cataract", "erpillar" or the    empty string.
  1089.  
  1090.       2. It    sets up    the subpattern as a capturing subpattern (as
  1091.       defined above).  When    the whole pattern matches, that
  1092.       portion of the subject string    that matched the subpattern is
  1093.       passed back to the caller via    the _o_v_e_c_t_o_r argument of
  1094.       ppppccccrrrreeee____eeeexxxxeeeecccc(((()))). Opening parentheses are counted from left to
  1095.       right    (starting from 1) to obtain the    numbers    of the
  1096.       capturing subpatterns.
  1097.  
  1098.       For example, if the string "the red king" is matched against
  1099.       the pattern
  1100.  
  1101.         the    ((red|white) (king|queen))
  1102.  
  1103.       the captured substrings are "red king", "red", and "king",
  1104.       and are numbered 1, 2, and 3.
  1105.  
  1106.       The fact that    plain parentheses fulfil two functions is not
  1107.       always helpful.  There are often times when a    grouping
  1108.       subpattern is    required without a capturing requirement. If
  1109.       an opening parenthesis is followed by    "?:", the subpattern
  1110.       does not do any capturing, and is not    counted    when computing
  1111.       the number of    any subsequent capturing subpatterns. For
  1112.       example, if the string "the white queen" is matched against
  1113.       the pattern
  1114.  
  1115.         the    ((?:red|white) (king|queen))
  1116.  
  1117.  
  1118.  
  1119.      Page 17                        (printed 12/10/98)
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.      PPPPCCCCRRRREEEE((((3333))))               UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV               PPPPCCCCRRRREEEE((((3333))))
  1127.  
  1128.  
  1129.  
  1130.       the captured substrings are "white queen" and    "queen", and
  1131.       are numbered 1 and 2.    The maximum number of captured
  1132.       substrings is    99, and    the maximum number of all subpatterns,
  1133.       both capturing and non-capturing, is 200.
  1134.  
  1135.  
  1136.  
  1137.      BBBBAAAACCCCKKKK RRRREEEEFFFFEEEERRRREEEENNNNCCCCEEEESSSS
  1138.       Outside a character class, a backslash followed by a digit
  1139.       greater than 0 (and possibly further digits) is a back
  1140.       reference to a capturing subpattern earlier (i.e. to its
  1141.       left)    in the pattern,    provided there have been that many
  1142.       previous capturing left parentheses. However,    if the decimal
  1143.       number following the backslash is less than 10, it is    always
  1144.       taken    as a back reference, and causes    an error if there have
  1145.       not been that    many previous capturing    left parentheses.  See
  1146.       the section entitled "Backslash" above for further details
  1147.       of the handling of digits following a    backslash.
  1148.  
  1149.       A back reference matches whatever actually matched the
  1150.       capturing subpattern in the current subject string, rather
  1151.       than anything    matching the subpattern    itself.    So the pattern
  1152.  
  1153.          (sens|respons)e and \1ibility
  1154.  
  1155.       matches "sense and sensibility" and "response    and
  1156.       responsibility", but not "sense and responsibility".
  1157.  
  1158.       There    may be more than one back reference to the same
  1159.       subpattern. If a subpattern has not actually been used in a
  1160.       particular match, then any back references to    it always
  1161.       fail.    For example, the pattern
  1162.  
  1163.         (a|(bc))\2
  1164.  
  1165.       always fails if it starts to match "a" rather    than "bc".
  1166.       Because there    may be up to 99    back references, all digits
  1167.       following the    backslash are taken as part of a potential
  1168.       back reference number. If the    pattern    continues with a digit
  1169.       character, then some delimiter must be used to terminate the
  1170.       back reference. If the PCRE_EXTENDED option is set, this can
  1171.       be whitespace.  Otherwise an empty comment can be used.
  1172.  
  1173.  
  1174.  
  1175.      RRRREEEEPPPPEEEETTTTIIIITTTTIIIIOOOONNNN
  1176.       Repetition is    specified by quantifiers, which    can follow any
  1177.       of the following items:
  1178.  
  1179.         a single character,    possibly escaped
  1180.         the    . metacharacter
  1181.         a character    class
  1182.  
  1183.  
  1184.  
  1185.      Page 18                        (printed 12/10/98)
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.      PPPPCCCCRRRREEEE((((3333))))               UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV               PPPPCCCCRRRREEEE((((3333))))
  1193.  
  1194.  
  1195.  
  1196.         a back reference
  1197.         a parenthesized subpattern
  1198.  
  1199.       The general repetition quantifier specifies a    minimum    and
  1200.       maximum number of permitted matches, by giving the two
  1201.       numbers in curly brackets (braces), separated    by a comma.
  1202.       The numbers must be less than    65536, and the first must be
  1203.       less than or equal to    the second. For    example:
  1204.  
  1205.         z{2,4}
  1206.  
  1207.       matches "zz",    "zzz", or "zzzz". A closing brace on its own
  1208.       is not a special character. If the second number is omitted,
  1209.       but the comma    is present, there is no    upper limit; if    the
  1210.       second number    and the    comma are both omitted,    the quantifier
  1211.       specifies an exact number of required    matches. Thus
  1212.  
  1213.         [aeiou]{3,}
  1214.  
  1215.       matches at least 3 successive    vowels,    but may    match many
  1216.       more,    while
  1217.  
  1218.         \d{8}
  1219.  
  1220.       matches exactly 8 digits. An opening curly bracket that
  1221.       appears in a position    where a    quantifier is not allowed, or
  1222.       one that does    not match the syntax of    a quantifier, is taken
  1223.       as a literal character. For example, "{,6}" is not a
  1224.       quantifier, but a literal string of four characters.
  1225.  
  1226.       The quantifier {0} is    permitted, causing the expression to
  1227.       behave as if the previous item and the quantifier were not
  1228.       present.
  1229.  
  1230.       For convenience (and historical compatibility) the three
  1231.       most common quantifiers have single-character    abbreviations:
  1232.  
  1233.         *     is equivalent to {0,}
  1234.         +     is equivalent to {1,}
  1235.         ?     is equivalent to {0,1}
  1236.  
  1237.       By default, the quantifiers are "greedy", that is, they
  1238.       match    as much    as possible (up    to the maximum number of
  1239.       permitted times), without causing the    rest of    the pattern to
  1240.       fail.    The classic example of where this gives    problems is in
  1241.       trying to match comments in C    programs. These    appear between
  1242.       the sequences    /* and */ and within the sequence, individual
  1243.       * and    / characters may appear. An attempt to match C
  1244.       comments by applying the pattern
  1245.  
  1246.         /\*.*\*/
  1247.  
  1248.  
  1249.  
  1250.  
  1251.      Page 19                        (printed 12/10/98)
  1252.  
  1253.  
  1254.  
  1255.  
  1256.  
  1257.  
  1258.      PPPPCCCCRRRREEEE((((3333))))               UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV               PPPPCCCCRRRREEEE((((3333))))
  1259.  
  1260.  
  1261.  
  1262.       to the string
  1263.  
  1264.         /* first command */     not comment  /* second    comment    */
  1265.  
  1266.       fails, because it matches the    entire string due to the
  1267.       greediness of    the .*    item.
  1268.  
  1269.       However, if a    quantifier is followed by a question mark,
  1270.       then it ceases to be greedy, and instead matches the minimum
  1271.       number of times possible, so the pattern
  1272.  
  1273.         /\*.*?\*/
  1274.  
  1275.       does the right thing with the    C comments. The    meaning    of the
  1276.       various quantifiers is not otherwise changed,    just the
  1277.       preferred number of matches.    Do not confuse this use    of
  1278.       question mark    with its use as    a quantifier in    its own    right.
  1279.       Because it has two uses, it can sometimes appear doubled, as
  1280.       in
  1281.  
  1282.          \d??\d
  1283.  
  1284.       which    matches    one digit by preference, but can match two if
  1285.       that is the only way the rest    of the pattern matches.
  1286.  
  1287.       If the PCRE_UNGREEDY option is set (an option    which is not
  1288.       available in Perl) then the quantifiers are not greedy by
  1289.       default, but individual ones can be made greedy by following
  1290.       they by a question mark. In other words, it inverts the
  1291.       default behaviour.
  1292.  
  1293.       When a parenthesized subpattern is quantified    with a minimum
  1294.       repeat count that is greater than 1 or with a    limited
  1295.       maximum, more    store is required for the compiled pattern, in
  1296.       proportion to    the size of the    minimum    or maximum.
  1297.  
  1298.       If a pattern starts with .* then it is implicitly anchored,
  1299.       since    whatever follows will be tried against every character
  1300.       position in the subject string.  PCRE    treats this as though
  1301.       it were preceded by \A.
  1302.  
  1303.       When a capturing subpattern is repeated, the value captured
  1304.       is the substring that    matched    the final iteration. For
  1305.       example,
  1306.  
  1307.          (tweedle[dume]{3})+\1
  1308.  
  1309.       matches "tweedledum tweedledee tweedledee" but not
  1310.       "tweedledum tweedledee tweedledum".
  1311.  
  1312.  
  1313.  
  1314.  
  1315.  
  1316.  
  1317.      Page 20                        (printed 12/10/98)
  1318.  
  1319.  
  1320.  
  1321.  
  1322.  
  1323.  
  1324.      PPPPCCCCRRRREEEE((((3333))))               UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV               PPPPCCCCRRRREEEE((((3333))))
  1325.  
  1326.  
  1327.  
  1328.      AAAASSSSSSSSEEEERRRRTTTTIIIIOOOONNNNSSSS
  1329.       An assertion is a test on the    characters following the
  1330.       current matching point that does not actually    consume    any of
  1331.       those    characters. The    simple assertions coded    as \b, \B, \A,
  1332.       \Z, ^    and $ are described above. More    complicated assertions
  1333.       are coded as subpatterns starting with (?= for positive
  1334.       assertions, and (?! for negative assertions. For example,
  1335.  
  1336.         \w+(?=;)
  1337.  
  1338.       matches a word followed by a semicolon, but does not include
  1339.       the semicolon    in the match, and
  1340.  
  1341.         foo(?!bar)
  1342.  
  1343.       matches any occurrence of "foo" that is not followed by
  1344.       "bar". Note that the apparently similar pattern
  1345.  
  1346.         (?!foo)bar
  1347.  
  1348.       does not find    an occurrence of "bar" that is preceded    by
  1349.       something other than "foo"; it finds any occurrence of "bar"
  1350.       whatsoever, because the assertion (?!foo) is always true
  1351.       when the next    three characters are "bar".
  1352.  
  1353.       Assertion subpatterns    are not    capturing subpatterns, and may
  1354.       not be repeated, because it makes no sense to    assert the
  1355.       same thing several times. If an assertion contains capturing
  1356.       subpatterns within it, these are always counted for the
  1357.       purposes of numbering    the capturing subpatterns in the whole
  1358.       pattern.  Substring capturing    is carried out for positive
  1359.       assertions, but it does not make sense for negative
  1360.       assertions.
  1361.  
  1362.       Assertions count towards the maximum of 200 parenthesized
  1363.       subpatterns.
  1364.  
  1365.  
  1366.  
  1367.      OOOONNNNCCCCEEEE----OOOONNNNLLLLYYYY SSSSUUUUBBBBPPPPAAAATTTTTTTTEEEERRRRNNNNSSSS
  1368.       The facility described in this section is available only
  1369.       when the PCRE_EXTRA option is    set at compile time. It    is an
  1370.       extension to Perl regular expressions.
  1371.  
  1372.       With both maximizing and minimizing repetition, failure of
  1373.       what follows normally    causes the repeated item to be re-
  1374.       evaluated to see if a    different number of repeats allows the
  1375.       rest of the pattern to match.    Sometimes it is    useful to
  1376.       prevent this,    either to change the nature of the match, or
  1377.       to cause it fail earlier than    it otherwise might when    the
  1378.       author of the    pattern    knows there is no point    in carrying
  1379.       on.
  1380.  
  1381.  
  1382.  
  1383.      Page 21                        (printed 12/10/98)
  1384.  
  1385.  
  1386.  
  1387.  
  1388.  
  1389.  
  1390.      PPPPCCCCRRRREEEE((((3333))))               UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV               PPPPCCCCRRRREEEE((((3333))))
  1391.  
  1392.  
  1393.  
  1394.       Consider, for    example, the pattern \d+foo when applied to
  1395.       the subject line
  1396.  
  1397.          123456bar
  1398.  
  1399.       After    matching all 6 digits and then failing to match    "foo",
  1400.       the normal action of the matcher is to try again with    only 5
  1401.       digits matching the \d+ item,    and then with 4, and so    on,
  1402.       before ultimately failing. Once-only subpatterns provide the
  1403.       means    for specifying that once a portion of the pattern has
  1404.       matched, it is not to    be re-evaluated    in this    way, so    the
  1405.       matcher would    give up    immediately on failing to match    "foo"
  1406.       the first time. The notation is another kind of special
  1407.       parenthesis, starting    with (?> as in this example:
  1408.  
  1409.         (?>
  1410.            +)bar
  1411.  
  1412.       This kind of parenthesis "locks up" the  part    of the pattern
  1413.       it contains once it has matched, and a failure further into
  1414.       the pattern is prevented from    backtracking into it.
  1415.       Backtracking past it to previous items, however, works as
  1416.       normal.
  1417.  
  1418.       For simple cases such    as the above example, this feature can
  1419.       be though of as a maximizing repeat that must    swallow
  1420.       everything it    can. So, while both \d+    and \d+? are prepared
  1421.       to adjust the    number of digits they match in order to    make
  1422.       the rest of the pattern match, (?>\d+) can only match    an
  1423.       entire sequence of digits.
  1424.  
  1425.       This construction can    of course contain arbitrarily
  1426.       complicated subpatterns, and it can be nested. Contrast with
  1427.       the \X assertion, which is a Prolog-like "cut".
  1428.  
  1429.  
  1430.  
  1431.      CCCCOOOOMMMMMMMMEEEENNNNTTTTSSSS
  1432.       The sequence (?# marks the start of a    comment    which
  1433.       continues up to the next closing parenthesis.    Nested
  1434.       parentheses are not permitted. The characters    that make up a
  1435.       comment play no part in the pattern matching at all.
  1436.  
  1437.       If the PCRE_EXTENDED option is set, an unescaped # character
  1438.       outside a character class introduces a comment that
  1439.       continues up to the next newline character in    the pattern.
  1440.  
  1441.  
  1442.  
  1443.      IIIINNNNTTTTEEEERRRRNNNNAAAALLLL FFFFLLLLAAAAGGGG SSSSEEEETTTTTTTTIIIINNNNGGGG
  1444.       If the sequence (?i) occurs anywhere in a pattern, it    has
  1445.       the effect of    setting    the PCRE_CASELESS option, that is, all
  1446.       letters are matched in a case-independent manner. The    option
  1447.  
  1448.  
  1449.  
  1450.      Page 22                        (printed 12/10/98)
  1451.  
  1452.  
  1453.  
  1454.  
  1455.  
  1456.  
  1457.      PPPPCCCCRRRREEEE((((3333))))               UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV               PPPPCCCCRRRREEEE((((3333))))
  1458.  
  1459.  
  1460.  
  1461.       applies to the whole pattern,    not just to the    portion    that
  1462.       follows it.
  1463.  
  1464.       If the sequence (?m) occurs anywhere in a pattern, it    has
  1465.       the effect of    setting    the PCRE_MULTILINE option, that    is,
  1466.       subject strings matched by this pattern are treated as
  1467.       consisting of    multiple lines.
  1468.  
  1469.       If the sequence (?s) occurs anywhere in a pattern, it    has
  1470.       the effect of    setting    the PCRE_DOTALL    option,    so that    dot
  1471.       metacharacters match newlines    as well    as all other
  1472.       characters.
  1473.  
  1474.       If the sequence (?x) occurs anywhere in a pattern, it    has
  1475.       the effect of    setting    the PCRE_EXTENDED option, that is,
  1476.       whitespace is    ignored    and # introduces a comment that    lasts
  1477.       till the next    newline. The option applies to the whole
  1478.       pattern, not just to the portion that    follows    it.
  1479.  
  1480.       If the sequence (?U) occurs anywhere in a pattern, it    has
  1481.       the effect of    setting    the PCRE_UNGREEDY option which inverts
  1482.       the greediness of quantifiers. This is an extension to
  1483.       Perl's facilities.
  1484.  
  1485.       If the sequence (?X) occurs in a pattern, it has the effect
  1486.       of setting the PCRE_EXTRA flag, which    turns on some
  1487.       additional features not found    in Perl.  This flag setting is
  1488.       special in that it must occur    earlier    in the pattern than
  1489.       any of the additional    features. It is    best put at the    start.
  1490.  
  1491.       If more than one option is required, they can    be specified
  1492.       jointly, for example as (?ix)    or (?mi).
  1493.  
  1494.  
  1495.  
  1496.      PPPPEEEERRRRFFFFOOOORRRRMMMMAAAANNNNCCCCEEEE
  1497.       Certain items    that may appear    in patterns are    more efficient
  1498.       than others. It is more efficient to use a character class
  1499.       like [aeiou] than a set of alternatives such as (a|e|i|o|u).
  1500.       In general, the simplest construction    that provides the
  1501.       required behaviour is    usually    the most efficient. Jeffrey
  1502.       Friedl's book    contains a lot of discussion about optimizing
  1503.       regular expressions for efficient performance.
  1504.  
  1505.       The use of PCRE_MULTILINE causes additional processing and
  1506.       should be avoided when it is not necessary. Caseless
  1507.       matching of character    classes    is more    efficient if
  1508.       PCRE_CASELESS    is set when the    pattern    is compiled.
  1509.  
  1510.  
  1511.  
  1512.      AAAAUUUUTTTTHHHHOOOORRRR
  1513.  
  1514.  
  1515.  
  1516.      PPPPaaaaggggeeee 22223333                        ((((pppprrrriiiinnnntttteeeedddd 11112222////11110000////99998888))))
  1517.  
  1518.  
  1519.  
  1520.  
  1521.  
  1522.  
  1523.      PPPPCCCCRRRREEEE((((3333))))               UUUUNNNNIIIIXXXX SSSSyyyysssstttteeeemmmm VVVV               PPPPCCCCRRRREEEE((((3333))))
  1524.  
  1525.  
  1526.  
  1527.       Philip Hazel <ph10@cam.ac.uk>
  1528.       University Computing Service,
  1529.       New Museums Site,
  1530.       Cambridge CB2    3QG, England.
  1531.       Phone: +44 1223 334714
  1532.  
  1533.       Copyright (c)    1998 University    of Cambridge.
  1534.  
  1535.  
  1536.  
  1537.  
  1538.  
  1539.  
  1540.  
  1541.  
  1542.  
  1543.  
  1544.  
  1545.  
  1546.  
  1547.  
  1548.  
  1549.  
  1550.  
  1551.  
  1552.  
  1553.  
  1554.  
  1555.  
  1556.  
  1557.  
  1558.  
  1559.  
  1560.  
  1561.  
  1562.  
  1563.  
  1564.  
  1565.  
  1566.  
  1567.  
  1568.  
  1569.  
  1570.  
  1571.  
  1572.  
  1573.  
  1574.  
  1575.  
  1576.  
  1577.  
  1578.  
  1579.  
  1580.  
  1581.  
  1582.      Page 24                        (printed 12/10/98)
  1583.  
  1584.  
  1585.  
  1586.